package com.test.base.mq;

import java.io.IOException;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;

import lombok.extern.slf4j.Slf4j;

/**
 * 消费者
 * @author: 许自辉     
 * @date: 2018年7月2日 下午4:10:11
 */
@Component

@Slf4j
public class MessageConsumer {
	
	@Autowired
	private WebSocketServerEndpoint webSocketServerEndpoint;
	
	@RabbitListener(queues = "message.queue")
	@RabbitHandler
    public void handler(@Payload MessageVO messageEntity) {
        log.info("消费内容：{}", JSON.toJSONString(messageEntity));
        try {
			webSocketServerEndpoint.sendInfo(JSON.toJSONString(messageEntity),null);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
